home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Modules / BackSpaceModules / Source / AquariumView / RotImage.m < prev    next >
Text File  |  1993-03-12  |  3KB  |  113 lines

  1. /*  
  2.  * From. . .
  3.  * MyImage.m    -- How to rotate an NXImage
  4.  * 
  5.  * This is a subclass of NXImage that supports rotation by overriding 
  6.  * drawRepresentation:inRect:
  7.  *
  8.  * You may freely copy, distribute, and reuse the code in this example.
  9.  * NeXT disclaims any warranty of any kind, expressed or  implied, as to its
  10.  * fitness for any particular use.
  11.  *
  12.  * Written by Henry Krempel -- NeXT Developer Support
  13.  *
  14.  * Wed Apr 10 17:39:50 1991
  15.  */
  16. #import "RotImage.h"
  17. #import <appkit/NXImage.h>
  18. #import <appkit/View.h>
  19. #import <dpsclient/wraps.h>
  20. #import <math.h>
  21. #import "wraps.h"
  22.  
  23.  
  24. @implementation RotImage
  25.  
  26.  
  27. - initFromFile:(const char *)fileName
  28. {
  29.     [super initFromFile:fileName];
  30.     [self getSize:&origSize];
  31.     rotSize.width=origSize.height;
  32.     rotSize.height=origSize.width;
  33.     currentSize=&origSize;
  34.     flipped=0;
  35.     return self;
  36. }
  37.  
  38. - initFromSection:(const char *)imageName
  39. {
  40.     [super initFromSection:imageName];
  41.     [self getSize:&origSize];
  42.     rotSize.width=origSize.height;
  43.     rotSize.height=origSize.width;
  44.     currentSize=&origSize;
  45.     flipped=0;
  46.     return self;
  47. }
  48.  
  49. /*
  50.  *
  51.  * drawRepresentation:inRect: override.  Any changes to the PostScript 
  52.  * transformation matrix can take effect here. Compositing normally ignores
  53.  * these changes,  but we are doing the transformation before the offscreen 
  54.  * NXImage is rendered,  then compositing this into our visible window.
  55.  *
  56.  */
  57.  
  58. - (BOOL)drawRepresentation:(NXImageRep *)imageRep inRect:(const NXRect *)rect
  59. {
  60.     if (NXDrawingStatus == NX_DRAWING) {    // Don't do this when printing
  61.     PSgsave();
  62.     NXSetColor (NX_COLORCLEAR);
  63.     NXRectFill (rect);
  64.     PSgrestore();
  65.     }
  66.     
  67.   /*
  68.    * The wrap below translates and rotates to the appropriate starting point,
  69.    * based on the rotation state (0 1 2 3) and the angle
  70.    */
  71.      
  72.     PSW_transformToFit(rotation, rotation, origSize.width, origSize.height);
  73.     
  74.     if (flippedHor) PSW_flipHor(origSize.width, origSize.height);
  75.     if (flippedVer) PSW_flipVer(origSize.width, origSize.height);
  76.             
  77.     return [super drawRepresentation:imageRep inRect:rect];
  78. }
  79.  
  80. /*
  81.  * Set the rotation of the image.  This will be one of 4 values 0..3 for the 
  82.  * four rotations we do here.  We only support these four since the size of
  83.  * these rectangles is easy to calculate.
  84.  *
  85.  */
  86.  
  87. - setRotation:(int)anInt
  88. {
  89.     NXSize *size;
  90.  
  91.     rotation = anInt;
  92.    
  93.     size=&rotSize;
  94.     
  95.         [self setSize:size];
  96.         [self recache];
  97.     currentSize=size;
  98.  
  99.     return self;
  100. }
  101.  
  102. - flip:(int)whichWay;
  103. {
  104.     if (whichWay == HORIZONTAL) flippedHor = (flippedHor+1) % 2;
  105.     else flippedVer = (flippedVer+1) % 2;
  106.     [self recache];
  107.     return self;
  108.  
  109. }
  110.  
  111. @end
  112.  
  113.